package nuig.prolog.userTypingFormat.impl;

import java.util.List;

import nuig.prolog.PrologAccess.impl.MeaningProcess;
import nuig.prolog.PrologAccess.impl.NormalSentenceProcess;
import nuig.prolog.PrologAccess.impl.WhoQuestionProcess;
import nuig.prolog.entity.WordEntity;
import nuig.prolog.userTypingFormat.Rule;

public class WhoQuestionRule extends Rule{

	@Override
	public Rule DoRule() throws Exception {

		WhoQuestionProcess WhoQuestionProcess = new WhoQuestionProcess();

		if (WhoQuestionProcess.isSuccess(GetString())) {

			//ReturnMessage.append("I understand this is a Normal sentence.");
			// meaning process
			MeaningProcess mean = new MeaningProcess();

			String keyWords = "";
			String People = "";

			for (WordEntity word : ProcessList) {
				if (word.getType().equals("er")) {
					keyWords = word.getWord();
				}

				if (word.getType().equals("people")) {
					People = word.getWord();
				}
			}

			String plcode = keyWords + "(X," + People + ").";
			//
			List<String> list= mean.GetAnswer(plcode);
			
			if(list.size()==0)
			{
				ReturnMessage.append(People+" is "+keyWords+" than all the people here.");
			}else
			{
				StringBuffer sb=new StringBuffer();
				for(String temp : list)
				{
					sb.append(temp);
					sb.append(",");
				}
				sb.deleteCharAt(sb.length()-1);
				ReturnMessage.append(sb.toString()+" is "+keyWords+" than " +People);
			}

		} else {

		}

		return this;

	}	
	

}
